define(['underscore', 'jquery'], function () {

    /* PRIVATE VARIABLES */
    var ajaxPointer;

    /* PRIVATE FUNCTIONS */


    /* PUBLIC FUNCTIONS */
    var pub = {};

    /**
     * Custom ajax call so we can normalize some behaviour
     * @param options - object
     *                  {
     *                      url: "REST/posts",
     *                      callback: function (data) {}
     *                  }
     */
    pub.call = function (options) {

        try {
            //ajaxPointer.abort();
        } catch (e) {
            console.log(e);
        }

        if (options.type == undefined) {
            options.type = 'GET';
        }

        if (options.data == undefined) {
            options.data = {};
        }

        $('#loading').addClass('active');
        ajaxPointer = $.ajax({
            url: "https://teeem-c9-nazzanuk.c9.io/" + options.url,
            type: options.type,
            data: options.data,
            dataType: 'jsonp', // Notice! JSONP <-- P (lowercase)
            success: function (data) {
                $('#loading').removeClass('active');
                console.log("success :", data);

                options.callback(data);
            },
            error: function (error) {
                $('#loading').removeClass('active');
                console.log("AJAX error :", error);
            }
        });
    };

    return pub;
});